﻿#include "extendwidget.h"

ExtendWidget::ExtendWidget(QWidget *parent, Qt::WindowFlags flags)
    : QWidget(parent, flags)
    , m_bWndPolish(0)
    , m_bWndShow(0)
    , m_bWndLayout(0)
    , m_bWndPaint(0)
{

}

ExtendWidget::~ExtendWidget()
{

}


bool ExtendWidget::event(QEvent *event)
{
    //事件顺序：POLISHED -> SHOWED -> LAYOUTED -> PAINTED
    if (m_bWndPolish == 0 && event->type() == QEvent::Polish)   //第一次Polish
    {
        m_bWndPolish = 1;

        //
        firstPolishEvent(event);

        //
        QEvent * ev = new QEvent(QEvent::Type(EVENT_FIRST_POLISHED));
        QApplication::postEvent(this, ev, Qt::LowEventPriority);
    }
    else if (m_bWndShow == 0 && event->type() == QEvent::Show)   //第一次显示
    {
        m_bWndShow = 1;

        //
        firstShowEvent(event);

        //
        QEvent * ev = new QEvent(QEvent::Type(EVENT_FIRST_SHOWED));
        QApplication::postEvent(this, ev, Qt::LowEventPriority);
    }
    else if (m_bWndLayout == 0 && event->type() == QEvent::LayoutRequest)   //第一次布局
    {
        m_bWndLayout = 1;

        //
        firstLayoutEvent(event);

        //
        QEvent * ev = new QEvent(QEvent::Type(EVENT_FIRST_LAYOUTED));
        QApplication::postEvent(this, ev, Qt::LowEventPriority);
    }
    else if (m_bWndPaint == 0 && event->type() == QEvent::Paint)    //第一次绘制
    {
        m_bWndPaint = 1;

        //
        firstPaintEvent(event);

        //
        QEvent * ev = new QEvent(QEvent::Type(EVENT_FIRST_PAINTED));
        QApplication::postEvent(this, ev, Qt::LowEventPriority);
    }
    else if (m_bWndPolish == 1 && event->type() == QEvent::Type(EVENT_FIRST_POLISHED))
    {
        m_bWndPolish = 2;

        //
        firstPolishedEvent(event);
    }
    else if (m_bWndShow == 1 && event->type() == QEvent::Type(EVENT_FIRST_SHOWED))
    {
        m_bWndShow = 2;

        //
        firstShowedEvent(event);
    }
    else if (m_bWndLayout == 1 && event->type() == QEvent::Type(EVENT_FIRST_LAYOUTED))
    {
        m_bWndLayout = 2;

        //
        firstLayoutedEvent(event);
    }
    else if (m_bWndPaint == 1 && event->type() == QEvent::Type(EVENT_FIRST_PAINTED))
    {
        m_bWndPaint = 2;

        //
        firstPaintedEvent(event);
    }

    //
    return __super::event(event);
}

void ExtendWidget::firstPolishEvent(QEvent *)
{

}

void ExtendWidget::firstPolishedEvent(QEvent *)
{

}

void ExtendWidget::firstShowEvent(QEvent *)
{

}

void ExtendWidget::firstShowedEvent(QEvent *)
{

}

void ExtendWidget::firstLayoutEvent(QEvent *)
{

}

void ExtendWidget::firstLayoutedEvent(QEvent *)
{

}

void ExtendWidget::firstPaintEvent(QEvent *)
{

}

void ExtendWidget::firstPaintedEvent(QEvent *)
{

}
